//
// PageTable.h
// Usage: Page table of a process
// CreateDate: 2009-03-26
// Author: MaJiuyue
//
#ifndef _PAGETABLE_H_
#define _PAGETABLE_H_ 

#include <NewLife.h>
#include "type.h"
#include "const.h"
#include "Map.h"
#include "Page.h"
#include "knlvar.h"

class PageTable
{
private:
	/* Page directory */
	pde_t * m_PageDirectory;

public:
	PageTable();
	PageTable(const PageTable& target);
	~PageTable();

public:
	/* Switch to address space of this PT */
	void SwitchTo();

	/* Sync UPD's KernelSpace with KPD */
	void SyncKPD();

	/* Clear page table, free all used page frame except for PD */
	void Clear();

	/* Map 2^order pages to user space */
	void MapUserSpace(addr_t vaddr, addr_t paddr, int order = 0);
	/* Do the opposite operation, unmap pages */ 
	void UnmapUserSpace(addr_t vaddr, int order = 0);
	/* Utillity function, return physical address of a virtual address */
	addr_t GetPhyAddress(addr_t vaddr);

public:
	/* Kernel page table */
	static pde_t * gKernelPageDirectory;
	static void InitializeKPD(pde_t * KernelPD);
	static void SetKPDE(int index, pde_t pde);
	static pde_t GetKPDE(int index);
	static void ClearKPDE(int index);
};

#endif

